package com.some;

import java.util.Scanner;

public class Test360_01 {
    public static int surfaceArea(int[][] grid) {//leetcode  892题
        int res = 0, init = 0, red = 0;
        if (grid == null || grid.length == 0)
            return 0;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                init += grid[i][j];
                if (i + 1 < grid.length && grid[i][j] > 0 && grid[i + 1][j] >= 1)
                    red += 2;
                if (j + 1 < grid[0].length && grid[i][j] > 0 && grid[i][j + 1] >= 1)
                    red += 2;
                if (grid[i][j] > 1) {
                    red += (grid[i][j] - 1) * 2;
                    if (i + 1 < grid.length && grid[i + 1][j] > 1)
                        red += (Math.min(grid[i][j], grid[i + 1][j]) - 1) * 2;
                    if (j + 1 < grid[0].length && grid[i][j + 1] > 1)
                        red += (Math.min(grid[i][j], grid[i][j + 1]) - 1) * 2;
                }
            }
        }
        res = 6 * init - red;
        return res;

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] m = new int[N][M];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < M; j++) {
                m[i][j] = sc.nextInt();
            }
        }
        System.out.println(surfaceArea(m));
    }
}

